<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <!-- 搜索 -->
        <label class="el-form-item-label">活动编号</label>
        <el-input v-model="query.id" clearable placeholder="活动编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">活动平台</label>
        <el-select v-model="query.plat" clearable size="small" placeholder="活动平台" class="filter-item" style="width: 110px"  @change="crud.toQuery">
          <el-option v-for="item in dict.plat" :key="item.id" :label="item.label" :value="item.value" />
        </el-select>
        <label class="el-form-item-label">是否隐藏地址</label>
        <el-select v-model="query.hide" clearable size="small" placeholder="是否隐藏地址" class="filter-item" style="width: 110px"  @change="crud.toQuery">
          <el-option v-for="item in dict.yn" :key="item.id" :label="item.label" :value="item.value" />
        </el-select>
        <label class="el-form-item-label">是否展示</label>
        <el-select v-model="query.ishow" clearable size="small" placeholder="是否展示" class="filter-item" style="width: 110px"  @change="crud.toQuery">
          <el-option v-for="item in dict.yn" :key="item.id" :label="item.label" :value="item.value" />
        </el-select>
        <date-range-picker
          v-model="query.createTime"
          start-placeholder="createTimeStart"
          end-placeholder="createTimeStart"
          class="date-item"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="'活动管理'" width="1000px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="250px">
          <el-form-item label="活动名称标题">
            <el-input v-model="form.activityName" style="width: 520px;" />
          </el-form-item>
          <el-form-item label="活动平台" prop="plat">
            <el-select v-model="form.plat" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.plat"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <!--<el-form-item label="活动开始时间" prop="startTime">
            <el-date-picker v-model="form.startTime" type="datetime" style="width: 520px;" />
          </el-form-item>
          <el-form-item label="活动结束时间" prop="endTime">
            <el-date-picker v-model="form.endTime" type="datetime" style="width: 520px;" />
          </el-form-item>-->
          <el-form-item label="返利类型" prop="ftype">
            <el-select v-model="form.ftype" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.ftype"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="返利比例(千分‰)">
            <el-input v-model="form.rate" placeholder="5个点请填50即可（千分五十），6.5个点填65"  style="width: 520px;" />
          </el-form-item>
          <el-form-item label="固返金额(单位：分)">
            <el-input v-model="form.ramt"  placeholder="5元请填500，用于精确计算"  style="width: 520px;" />
          </el-form-item>
          <el-form-item label="是否展示" prop="show">
            <el-select v-model="form.ishow" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.yn"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="仅展示的媒体编号">
            <el-input v-model="form.showUid" :rows="3"  placeholder="多个用逗号分开"   type="textarea" style="width: 520px;" />
          </el-form-item>
          <!--  <el-form-item label="活动类型">
            <el-input v-model="form.atype" style="width: 520px;" />
          </el-form-item>  -->
          <el-form-item label="结算周期">
            <el-input v-model="form.zhouqi" style="width: 520px;" />
          </el-form-item>
          <el-form-item label="简介">
            <el-input v-model="form.jianjie" :rows="3" type="textarea" style="width: 520px;" />
          </el-form-item>
          <el-form-item label="活动说明">
            <el-input v-model="form.shuoming" :rows="3" type="textarea" style="width: 520px;" />
          </el-form-item>
          <!--<el-form-item label="主图地址">
            <el-input v-model="form.mianImg" style="width: 520px;" />
          </el-form-item>
          <el-form-item label="扩展图片1">
            <el-input v-model="form.img1" style="width: 520px;" />
          </el-form-item>-->
          <el-form-item label="主链接（真实需要隐藏的链接）">
            <el-input v-model="form.mianUrl" style="width: 520px;" />
          </el-form-item>
          <el-form-item label="是否隐藏地址" prop="hide">
            <el-radio v-model="form.hide" v-for="item in dict.yn" :key="item.id" :label="item.value">{{ item.label }}</el-radio>
          </el-form-item>
          <el-form-item label="访问地址（自动生成）">
            <el-input v-model="form.hideUrl" style="width: 520px;" disabled />
          </el-form-item>
          <!--<el-form-item label="创建时间">
            <el-date-picker v-model="form.createTime" type="datetime" style="width: 520px;" />
          </el-form-item>-->
          <el-form-item label="订单总额度">
            <el-input v-model="form.orderEdu" style="width: 520px;" />
          </el-form-item>
          <el-form-item label="剩余额度">
            <el-input v-model="form.shengyuEdu" style="width: 520px;" />
          </el-form-item>

          <el-form-item label="报单必填字段配置：">


            <label class="el-form-item-label">必填订单金额</label>
            <el-select v-model="form.swamt" filterable placeholder="请选择" style="width: 80px;">
              <el-option
                v-for="item in dict.yn"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>

            <label class="el-form-item-label">必填数量</label>
            <el-select v-model="form.swcount" filterable placeholder="请选择" style="width: 80px;">
              <el-option
                v-for="item in dict.yn"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>


            <label class="el-form-item-label">必填售价</label>
            <el-select v-model="form.swshoujia" filterable placeholder="请选择" style="width: 80px;">
              <el-option
                v-for="item in dict.yn"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>

          </el-form-item>

          <el-form-item label="">
            <label class="el-form-item-label">必填订单时间</label>
            <el-select v-model="form.swtime" filterable placeholder="请选择" style="width: 80px;">
              <el-option
                v-for="item in dict.yn"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>

            <label class="el-form-item-label">必填微信</label>
            <el-select v-model="form.swuname" filterable placeholder="请选择" style="width: 80px;">
              <el-option
                v-for="item in dict.yn"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>

            <label class="el-form-item-label">必填备注</label>
            <el-select v-model="form.swextra1" filterable placeholder="请选择" style="width: 80px;">
              <el-option
                v-for="item in dict.yn"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>

          </el-form-item>



        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="活动编号" />
        <el-table-column prop="activityName" label="活动名称标题" />
        <el-table-column prop="plat" label="活动平台">
          <template slot-scope="scope">
            {{ dict.label.plat[scope.row.plat] }}
          </template>
        </el-table-column>
        <!--<el-table-column prop="atype" label="活动类型" />-->
        <!--<el-table-column prop="zhouqi" label="结算周期" />-->
        <!--<el-table-column prop="startTime" label="活动开始时间" />-->
        <!--<el-table-column prop="endTime" label="活动结束时间" />-->
        <!--<el-table-column prop="lastUpdateTime" label="最后更新时间" />
        <el-table-column prop="jianjie" label="简介" />
        <el-table-column prop="shuoming" label="活动说明" />
        <el-table-column prop="mianImg" label="主图地址" />
        <el-table-column prop="img1" label="扩展图片1" />-->
        <!--<el-table-column prop="mianUrl" label="主链接" />
        <el-table-column prop="orderUrl" label="报单地址" />-->
        <el-table-column prop="hide" label="是否隐藏地址">
          <template slot-scope="scope">
            {{ dict.label.yn[scope.row.hide] }}
          </template>
        </el-table-column>
        <!--<el-table-column prop="hideUrl" label="访问地址" />-->
        <el-table-column prop="ftype" label="返利类型">
          <template slot-scope="scope">
            {{ dict.label.ftype[scope.row.ftype] }}
          </template>
        </el-table-column>
        <el-table-column prop="rate" label="返利比例（千分之‰）" />
        <el-table-column prop="ramt" label="固返金额" />
        <el-table-column prop="ishow" label="是否展示">
          <template slot-scope="scope">
            {{ dict.label.yn[scope.row.ishow] }}
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="orderEdu" label="订单总额度" />
        <el-table-column prop="shengyuEdu" label="剩余额度" />
        <el-table-column v-if="checkPer(['admin','activity:edit','activity:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudActivity from '@/api/activity/activity'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
const defaultForm = { id: null, activityName: null, plat: null, atype: null, zhouqi: null, startTime: null, endTime: null, lastUpdateTime: null, jianjie: null, shuoming: null, mianImg: null, img1: null, mianUrl: null, orderUrl: null, hide: null, hideUrl: null, createTime: null, orderEdu: null, shengyuEdu: null, ftype: null, rate: null, ramt: null, show: null, shouUid: null, swcount: null, swamt: null, swshoujia: null, swtime: null, swuname: null, swextra1: null }
export default {
  name: 'Activity',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['plat', 'yn', 'ftype'],
  cruds() {
    return CRUD({ title: 'activity', url: 'api/activity', idField: 'id', sort: 'id,desc', crudMethod: { ...crudActivity }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'activity:add'],
        edit: ['admin', 'activity:edit'],
        del: ['admin99', 'activity:del1']
      },
      rules: {
        id: [
          { required: true, message: '活动编号不能为空', trigger: 'blur' }
        ],
        activityName: [
          { required: true, message: '活动名称标题不能为空', trigger: 'blur' }
        ],
        plat: [
          { required: true, message: '活动平台不能为空', trigger: 'blur' }
        ],
        ftype: [
          { required: true, message: '返利类型不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'id', display_name: '活动编号' },
        { key: 'plat', display_name: '活动平台' },
        { key: 'hide', display_name: '是否隐藏地址' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
